package com.roadmap.client.common;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import com.roadmap.common.BaseEntity;

public class SimpleResultSet implements ISimpleResultSet {
	private final Hashtable<String, Object> container;

	public SimpleResultSet() {
		container = new Hashtable<String, Object>();
	}

	public void add(BaseEntity entity) {
		if (entity == null)
			return;

		container.put(entity.getId(), entity);
	}

	public void add(String id, Object entity) {
		if (entity == null || id == null)
			return;

		container.put(id, entity);
	}

	public void cleanup() {
		container.clear();
	}

	public Object get(String id) {
		if (id == null)
			return null;

		return container.get(id);
	}

	public List<BaseEntity> getAll() {
		List entities = new ArrayList<BaseEntity>();
		Iterator iter = container.values().iterator();
		while (iter.hasNext()) {
			Object ent = iter.next();
			if (ent != null)
				entities.add(ent);
		}

		return entities;
	}

	public boolean hasKey(String id) {
		if (id == null)
			return false;

		return container.contains(id);
	}

	public int getSize() {
		return container.size();
	}
	

}
